package com.example.wanbaqian.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.wanbaqian.R;
import com.example.wanbaqian.base.BaseActivity;
import com.example.wanbaqian.config.CommonValue;
import com.example.wanbaqian.base.HttpCallback;
import com.example.wanbaqian.config.HttpURL;
import com.example.wanbaqian.bean.Info;
import com.example.wanbaqian.utils.GetJsonUtils;
import com.example.wanbaqian.utils.HttpUtils;
import com.example.wanbaqian.utils.JsonUtils;
import com.example.wanbaqian.utils.SPUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 代理商提现界面
 */
public class FindWithDrawalActivity extends BaseActivity implements HttpCallback {
    @BindView(R.id.edi_money)
    EditText ediMoney;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_id)
    TextView tvId;
    @BindView(R.id.tv_sxf)
    TextView tv_sxf;
    @BindView(R.id.tv_money)
    TextView tv_money;
    private Bundle bundle;

    @Override
    protected int getLayout() {
        return R.layout.activity_findwithdrawal;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setStatusBarColor(R.color.balck);
        setToolBar("提现");
        bundle = getIntent().getExtras();
        toolBar_tvRight.setText("提现记录");
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        toolBar_tvRight.setVisibility(View.VISIBLE);
        toolBar_tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                openActivity(FindWithDrawalListActivity.class);
            }
        });
    }

    @Override
    protected void initDate() {
        if (null != bundle) {
            tv_money.setText("奖金余额  " + bundle.getString("money"));
            tvName.setText(JsonUtils.getInstance().getJsonObject(bundle.getString("bank_info"), "bank_name"));
            tvId.setText(JsonUtils.getInstance().getJsonObject(bundle.getString("bank_info"), "bank_account"));
            tv_sxf.setText("提现手续费" + JsonUtils.getInstance().getJsonObject(bundle.getString("bank_info"), "cash_fee") + "元/笔");
        }
    }

    @OnClick(R.id.btn_ok)
    public void onViewClicked() {
        String moneyStr = ediMoney.getText().toString();
        if (TextUtils.isEmpty(moneyStr)) {
            showToast("提现金额不能为空");
            return;
        } else if (Double.parseDouble(moneyStr) < 1) {
            showToast("提现金额不能小于1元");
            return;
        } else {
            HttpUtils.getInstance().post(GetJsonUtils.getInstance().getRequest(HttpURL.WITHDRAW_APPLY, mContext,
                    new String[]{"accessid", "withdraw_money"}, new Object[]{SPUtils.getAccessid(mContext), Double.parseDouble(moneyStr)})
                    , null, CommonValue.REQUEST_CODE2, this);
        }
    }

    @Override
    public void onSuccess(String content, Info info, int requestCode) {
        switch (requestCode) {
            case CommonValue.REQUEST_CODE2:
                showToast("提现成功");
                finish();
                break;
        }
    }

    @Override
    public void onCacheSuccess(String content, Info info, int requestCode) {

    }

    @Override
    public void onError(Info info, int requestCode) {
        showToast(info.getMsg());
    }
}
